Post

Replies

Boosts

Views

Activity

Reply to ShareLink with custom Transferable struct using FileRepresentation not working as expected
I noticed similar behaviour on iOS and worked around it using ProxyRepresentation, a bit like this: struct DataShareItem: Transferable { static var transferRepresentation: some TransferRepresentation { ProxyRepresentation { try generateFile() } } var data: Data var filename: String private func generateFile() throws → URL { let tempFileURL = FileManager.default.temporaryDirectory .appendingPathComponent(filename) try data.write(to: tempFileURL) return tempFileURL } } I agree that it seems like the FileRepresentation approach should work though, so I think it's a framework bug.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’25
Reply to 'Save to Files' doesn't work with ShareLink with FileRepresentation
I encountered this problem as well. It does not affect iOS 16, but does affect iOS 17 and 18. It's reproducible in the simulator as well as on device. In my case I was able to use DataRepresentation with a suggestedFileName instead. In this example, it would look like this: struct TextFile: Transferable { let content: String let filename: String static var transferRepresentation: some TransferRepresentation { DataRepresentation(exportedContentType: .data) { textFile in return textFile.content.data(using: .utf8) ?? Data() } .suggestedFileName { textFile in return textFile.filename } } } Caveats: Requires iOS 17+ if you want to use this suggestedFileName method. Isn't feasible for large files that won't fit in memory.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’24